#include<bits/stdc++.h>
using namespace std;
#define num first
#define loc second
const int MAXN=1e5+10,INF=0x3f3f3f3f;
int n,k,a[MAXN],nxt[MAXN],last[MAXN],ans;
bool operator<(const pair<int,int> a,const pair<int,int> b)
{
	return a.num<b.num;
}
multiset<pair<int,int> >s;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=n;i;--i)a[i]-=a[i-1];
	a[1]=a[n+1]=INF;
	for(int i=1;i<=n+1;++i)
	{
		s.insert(make_pair(a[i],i));
		nxt[i]=i+1;
		last[i]=i-1;
	}
	while(k--)
	{
		multiset<pair<int,int> >::iterator iter=s.begin();
		//for(;iter!=s.end();++iter)printf("%d %d\n",(*iter).num,(*iter).loc);
		//printf("\n");
		iter=s.begin();
		int i=(*iter).loc,k1=a[last[i]],k2=a[nxt[i]];
		ans+=(*iter).num;
		s.erase(make_pair(k1,last[i]));
		s.erase(make_pair(k2,nxt[i]));
		last[i]=last[last[i]];
		nxt[i]=nxt[nxt[i]];
		nxt[last[i]]=i;
		last[nxt[i]]=i;
		a[i]=k1+k2-(*iter).num;
		s.erase(*iter);
		s.insert(make_pair(a[i],i));
	}
	printf("%d\n",ans);
	return 0;
}
